package com.pureut.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pureut.common.security.utils.SecurityUtils;
import com.pureut.system.domain.SampleRequirement;
import com.pureut.system.domain.dto.SampleRequirementDetailsDto;
import com.pureut.system.domain.vo.SampleRequirementVo;
import com.pureut.system.mapper.SampleRequirementMapper;
import com.pureut.system.service.ISampleRequirementService;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * @Author: pureut
 * @Date: 2024-12-04 16:59:44
 * @Desc: 样品需求
 */
@Service("sampleRequirementService")
public class SampleRequirementServiceImpl extends ServiceImpl<SampleRequirementMapper, SampleRequirement> implements ISampleRequirementService {

    /**
     * 样品需求Dao
     */
    @Resource
    private SampleRequirementMapper sampleRequirementMapper;

    /**
     * 查询列表
     * @param sampleRequirementVo
     * @return
     */
    @Override
    public List<SampleRequirement> queryPage(SampleRequirementVo sampleRequirementVo) {

        // 总数、结果
//        return sampleRequirementDao.selectPage(page, wrapper);
        return null;
    }


    /**
     * 新增样品需求
     * @param sampleRequirementVo
     * @return
     */
    @Override
    public Boolean save(SampleRequirementVo sampleRequirementVo) {
        SampleRequirement sampleRequirement = new SampleRequirement();
        BeanUtil.copyProperties(sampleRequirementVo, sampleRequirement);
        sampleRequirement.setCreateBy(SecurityUtils.getUsername());
        sampleRequirement.setCreateTime(new Date());
        return save(sampleRequirement);
    }


    /**
     * 更新样品需求
     * @param sampleRequirementVo
     * @return
     */
    @Override
    public Boolean updateById(SampleRequirementVo sampleRequirementVo) {
        SampleRequirement sampleRequirement = new SampleRequirement();
        BeanUtil.copyProperties(sampleRequirementVo, sampleRequirement);
        sampleRequirement.setUpdateBy(SecurityUtils.getUsername());
        sampleRequirement.setUpdateTime(new Date());
        return updateById(sampleRequirement);
    }

    /**
     * 根据样品申请单id查询list
     * @param id
     * @return
     */
    @Override
    public List<SampleRequirementDetailsDto> getListBySamlpleId(Long id){
        return sampleRequirementMapper.getListBySamlpleId(id);
    }
}
